import org.junit.Test;

import java.util.Arrays;
import java.util.Random;
import java.util.function.BiConsumer;
import java.util.function.IntConsumer;

public class RandomNumber {

    @Test
    public void test(){
        String sixNum = getSixNum();
        System.out.println(sixNum);
    }

    public static String getSixNum() {
        String str = "0123456789";
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 6; i++) {
            char ch = str.charAt(new Random().nextInt(str.length()));
            sb.append(ch);
        }
        return sb.toString();
    }

    @Test
    public void test2(){
        Random random = new Random();
        int i = random.nextInt(10);
        System.out.println(i);
    }

    @Test
    public void test3(){
        int[] ints = randomNum(6);
        System.out.println(ints);
    }

    @Test
    public void test4(){
        String numStr = randomNumStr(6);
        System.out.println(numStr);
    }


    public static int[] randomNum(int len){
        int[] result = new int[len];

        randomNum(len, (v, i)-> result[i]= v );

        return result;
    }

    public static String randomNumStr(int len){
        StringBuilder sb = new StringBuilder(len);

        randomNum(len, sb::append );
        return sb.toString();
    }

    public static void randomNum(int len, IntConsumer consumer){
        randomNum(len, (v,i)->consumer.accept(v));
    }

    public static void randomNum(int len, BiConsumer<Integer, Integer> consumer){
        Random random = new Random();
        for (int i = 0; i < len; i++) {
            consumer.accept(random.nextInt(10), i);
        }
    }

}
